package com.warm.gen.methodmodel;

import com.warm.gen.util.GenUtils;
import com.warm.core.constant.GenConstants;
import freemarker.template.TemplateMethodModelEx;
import org.noear.solon.annotation.Component;

import java.util.List;

/**
 * 获取长度
 *
 * @author warm
 */

@Component("share:LengthTemplate")
public class LengthTemplate implements TemplateMethodModelEx {
    /**
     * 获取字符串或者精度长度
     */
    @Override
    public Object exec(List args) {
        String columnType = args.get(0).toString();
        String dataType = GenUtils.getDbType(columnType);
        if (GenUtils.arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) {
            Integer columnLength = GenUtils.getColumnLength(columnType);
            return String.valueOf(columnLength);
        }
        return "";
    }

}
